import collections


class HitCounter:

    def __init__(self):
        self.d = collections.deque()
        self.count = 0

    def hit(self, timestamp: int) -> None:
        self.d.append(timestamp)
        self.count += 1

    def getHits(self, timestamp: int) -> int:
        while self.d and timestamp - self.d[0] >= 300:
            self.d.popleft()
            self.count -= 1
        return self.count
